home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / game / patch / TotalFootb2HD.lha / totalhd.s < prev   
Text File  |  1980-01-06  |  12KB  |  481 lines

  1.  
  2. ;/* Total Football - Fastram loader (HD Installer)
  3.   * ----------------------------------------------
  4.   * Requirements: 3MB of free continious fastram available (for the 3
  5.   * mirrored game disks)
  6.   *
  7.   * This source code is provided here so that;
  8.   *
  9.   * 1) Domark may possibly learn from it ... hehehe :)
  10.   * 2) Other people (assembly coders) can fix all these types of game to work
  11.   *    from hard-disk with ease...
  12.   *
  13.   * This source is fully freeware! do what you wish with it!
  14.   *
  15.   * Even use it in commercial games if you want.. go on see if I care!
  16.   *
  17.   */
  18.  
  19. _custom            =    $DFF000
  20. intena            =    $9A
  21. color            =    $180
  22. dmacon            =    $96
  23. fmode            =    $1fc
  24. bplcon3            =    $106
  25.  
  26. AbsExecBase        =    $4
  27. MaxLocMem        =    $3E
  28. MaxExtMem        =    $4E
  29. AttnFlags        =    $128
  30.  
  31. tv_UserIntVects        =    $100
  32. tv_TrapInstrVects    =    $80
  33.  
  34. _LVOSupervisor        =    -30
  35. _LVOOldOpenLibrary    =    -408
  36. _LVOFindTask        =    $FFFFFEDA
  37. _LVOWaitPort        =    $FFFFFE80
  38. _LVOGetMsg        =    $FFFFFE8C
  39. _LVOReplyMsg        =    $FFFFFE86
  40. _LVOForbid        =    $FFFFFF7C
  41. _LVOPermit        =    $FFFFFF76
  42. _LVOOpen        =    $FFFFFFE2
  43. _LVORead        =    $FFFFFFD6
  44. _LVOClose        =    $FFFFFFDC
  45.         
  46. pr_CLI            =    $AC
  47. pr_MsgPort        =    $5C
  48.  
  49. MODE_OLDFILE        =    $3ED
  50.  
  51. CACRF_CopyBack        =    $80000000    * Enable Copyback mode (`040+)
  52. CACRF_EnableE        =    $40000000    * Enable External Caches
  53. CACRF_WriteAllocate    =    $00002000    * Enable Write Allocate (`030+)
  54. CACRF_DBE        =    $00001000    * Data Burst (`030+)
  55. CACRF_ClearD        =    $00000800    * Flush Data Cache (`030+)
  56. CACRF_FreezeD        =    $00000200    * Freeze Data Cache (`030+)
  57. CACRF_EnableD        =    $00000100    * Enable Data Cache (`030+)
  58. CACRF_IBE        =    $00000010    * Inst Burst (`030+)
  59. CACRF_ClearI        =    $00000008    * Flush Inst Cache (`020+)
  60. CACRF_FreezeI        =    $00000002    * Freeze Inst Cache (`020+)
  61. CACRF_EnableI        =    $00000001    * Enable Inst Cache (`020+)
  62.  
  63. * Enable Instruction-cache()
  64. * Enable Data-cache()
  65. * Enable Write-allocate()
  66.  
  67.         section    fastram,code_f
  68.  
  69. *-------------- handle a workbench startup..
  70.  
  71. HD_Install:    move.l    d0,d7            ;save CLI params len
  72.         move.l    a0,a5            ;save CLI params ptr
  73.         suba.l    a1,a1            ;clear a1
  74.         move.l    4.w,a6            ;get execbase
  75.         jsr    _LVOFindTask(a6)    ;find *THIS* task
  76.         move.l    d0,a4            ;get task ptr
  77.         move.l    d7,d0            ;restore CLI params len
  78.         move.l    a5,a0            ;restore CLI params ptr
  79.         tst.l    pr_CLI(a4)        ;did we originate from CLI?
  80.         bne.s    ProgStart        ;yes...call our program
  81.  
  82.         lea    pr_MsgPort(a4),a0    ;from wb.. handle wb_startup
  83.         move.l    a0,a4
  84.         jsr    _LVOWaitPort(a6)    ;wait for a message
  85.         move.l    a4,a0
  86.         jsr    _LVOGetMsg(a6)        ;then get it
  87.         move.l    d0,-(sp)
  88.         bsr.s    ProgStart
  89.  
  90.         move.l    d0,d7            ;save CLI Return code
  91.         move.l    4.w,a6
  92.         jsr    _LVOForbid(a6)
  93.         move.l    (sp)+,a1
  94.         jsr    _LVOReplyMsg(a6)
  95.         move.l    d7,d0            ;exit code
  96.         rts
  97.  
  98. ProgStart    move.l    4.w,a6
  99.         lea    DOSName(pc),a1        * lib name in a1
  100.           jsr    _LVOOldOpenLibrary(a6)    * try to open library
  101.           move.l    d0,_DOSBase        * store lib base
  102.           beq.w    bad_file        * cleanup and quit if fail
  103.  
  104. *-------------- load disk 1 mirror into fastram..
  105.  
  106.         lea    disk1.txt(pc),a0
  107.         lea    diskdata+901120*0,a1
  108.         bsr    RealLoadDOSFile
  109.         tst.l    d0
  110.         bne.w    bad_file
  111.  
  112. *-------------- load disk 2 mirror into fastram..
  113.         
  114.         lea    disk2.txt(pc),a0
  115.         lea    diskdata+901120*1,a1
  116.         bsr    RealLoadDOSFile
  117.         tst.l    d0
  118.         bne.w    bad_file
  119.  
  120. *-------------- load disk 3 mirror into fastram..
  121.  
  122.         lea    disk3.txt(pc),a0
  123.         lea    diskdata+901120*2,a1
  124.         bsr    RealLoadDOSFile
  125.         tst.l    d0
  126.         bne.w    bad_file
  127.  
  128. *-------------- now take over machine now..
  129.  
  130.         move.l    4.w,a6
  131.         lea    Caches(pc),a5
  132.         jmp    _LVOSupervisor(a6)    * enter supervise mode!
  133.  
  134. *-------------- turn off all dma, interrupts, etc.        
  135.  
  136. Caches:        move.w    #$7FFF,$dff096        * no dmacon
  137.         move.w    #$7FFF,$dff09a        * no intena
  138.         move.w    #$7FFF,$dff09c        * no intreq
  139.  
  140. *-------------- patch AGA hardware to reset to defaults (null)
  141.  
  142.         move.w    #$0,_custom+fmode    * no AGA 64-bit fetchmodes..
  143.         move.w    #$0,_custom+bplcon3    * no extra bitplane control
  144.  
  145. *-------------- turn OFF cpu caches.. (sob!)
  146.  
  147.         move.l    #CACRF_FreezeI+CACRF_FreezeD+CACRF_WriteAllocate,d0
  148.         movec    d0,cacr
  149.  
  150. *-------------- reset vectorbase to zeropage 
  151.         moveq    #0,d0
  152.         movec    d0,vbr
  153.  
  154. *-------------- init our fastram loader..
  155.  
  156.         lea    diskdata,a0        * disk image`s buffer
  157.         lea    blockmem,a1        * 512 Bytes fastram buffer
  158.         jsr    InitDOSLoad        
  159.  
  160. *-------------- load in the game loader..
  161.  
  162. * NB:
  163. * ---
  164. * All these lame and dirty absolute addresses are needed because the original
  165. * game is address relocated to $19268 in chipram!! ARRRGG!!!!! Wake up DOMARK!
  166. *
  167.  
  168.         lea    chipload.txt(pc),a0
  169.         lea    $19268,a1
  170.         jsr    fastload
  171.  
  172. *-------------- re-direct he game`s hardware disk loader to our fastram loader
  173.  
  174.         move.l    (AbsExecBase).l,a6
  175.         lea    ($4000).l,sp         * set absolute stack (doh!)
  176.         lea    (tv_UserIntVects).l,a0 
  177.         move.w    (AttnFlags,a6),($2F6,a0) * total football`s main
  178.         move.l    (MaxLocMem,a6),($2F8,a0) * loader expect`s at these
  179.         move.l    (MaxExtMem,a6),($2FC,a0) * low memory addresses to
  180.         move.l    #$480,$400.w         * have these variables
  181.         move.l    #$880,$404.w             * which is pretty lame eh!
  182.  
  183.         lea    $19268,a0        * a0.l = base of game loader
  184.  
  185.         move.w    #$4e75,$2500(a0)    * no drive select grinds
  186.                         * patched to simply "RTS"
  187.                         
  188.         move.w    #$4ef9,$25e6(a0)    * patch loader to "JMP" to the
  189.         move.l    #fastload,$25e6+2(a0)    * address of our 'fastload'
  190.     
  191.         move.w    #$600e,$23e0(a0)    * skip past disk select checks
  192.                         * patched to "BRA.S"..
  193.                         
  194.         jmp    (a0)            * jump into the game!
  195.  
  196.         cnop    0,4
  197. RealLoadDOSFile:
  198.         move.l    a1,a4
  199.         move.l    a0,d1
  200.         move.l    #MODE_OLDFILE,d2    * open mode
  201.         move.l    _DOSBase,a6
  202.         jsr    _LVOOpen(a6)        * open file
  203.         move.l    d0,d6            * save filehandle
  204.         beq.s    err            * open error result?
  205.         move.l    d6,d1            * filehandle
  206.         move.l    a4,d2            * buffer
  207.         move.l    #901120,d3        * l = length read
  208.         jsr    _LVORead(a6)        * call Read/Write
  209.         move.l    d0,d2            * save read length
  210.         beq.s    err
  211.         move.l    d6,d1            * filebuffer
  212.         jsr    _LVOClose(a6)        * Close File
  213.         moveq    #0,d0
  214.         rts
  215. err:        moveq    #-1,d0
  216.         rts
  217.  
  218. bad_file:    move.w    #$f00,$dff180        * red flash of screen..
  219.  
  220.         moveq    #5,d0            * exit to dos.. (warn)
  221.         rts
  222.  
  223. _DOSBase    dc.l    0
  224. DOSName:    dc.b    'dos.library',0
  225.         even
  226. chipload.txt:    dc.b    'chipram.exe',0
  227.         even
  228. disk1.txt:    dc.b    'total:total1',0
  229. disk2.txt:    dc.b    'total:total2',0
  230. disk3.txt:    dc.b    'total:total3',0
  231.  
  232.         cnop    0,4
  233. fastload:    movem.l    d0-a6,-(sp)
  234.         moveq    #0,d0            * d0.w = disk to load from
  235.         bsr.b    LoadDOSFile
  236.         movem.l    (sp)+,d0-a6
  237.  
  238.         movem.l    d0-a6,-(sp)
  239.         moveq    #1,d0            * d0.w = disk to load from
  240.         bsr.b    LoadDOSFile
  241.         movem.l    (sp)+,d0-a6
  242.  
  243.         movem.l    d0-a6,-(sp)
  244.         moveq    #2,d0            * d0.w = disk to load from
  245.         bsr.b    LoadDOSFile
  246.         movem.l    (sp)+,d0-a6
  247.  
  248.         moveq    #0,d0
  249.         rts
  250.  
  251. * FASTRAM AmigaDOSFile Loader
  252. * ---------------------------
  253. * $Inputs:    a0.l = filename
  254. *        a1.l = load buffer
  255. *        d0.w = number of disk to load from..
  256. *
  257. * $Outputs:    d0.l = resultcode
  258. *
  259.  
  260. error        =    0    * 0-1 (.W)
  261. disk_number    =    1    * 1-2 (.W)
  262. load_address     =    2    * 2-6 (.L)
  263.  
  264. LoadBase:    bra.b    LoadDOSFile        * 00 jump table..
  265.         bra.w    InitDOSLoad        * 01
  266.  
  267.         cnop    0,4            * quad aligned..
  268. LoadDOSFile:    movem.l d2-d7/a0-a4/a6,-(a7)
  269.         move.l    a0,a6
  270.         move.l    a1,a5
  271.         move.l    a5,-(sp)
  272.         bsr.b    Find_file
  273.         move.l    (sp)+,d1
  274.         sub.l    a5,d1
  275.         moveq    #0,d0            * d0.l = result code..
  276.         move.b    (a2),d0
  277.         neg.l    d1            * d1.l = load length..
  278.         movem.l (a7)+,d2-d7/a0-a4/a6
  279.         rts
  280.  
  281.         cnop    0,4
  282. Find_file    lea    variables(pc),a2
  283.         move.b    d0,disk_number(a2)
  284.         move.l    a5,load_address(a2)
  285.         clr.b    (a2)
  286.         move.l    blockbuff_ptr(pc),a0    * get disk's root dir.
  287.         move.w    #880,d0
  288.         bsr.w    Get_block
  289.         tst.b    (a2)
  290.         bne.w    file_eror
  291. find_files_root_dir_loop
  292.         move.l    a6,a4
  293.         moveq    #0,d0    
  294. dir_loop    move.b    (a4),d7            * find file's root dir
  295.         beq.s    root_dir
  296.         cmpi.b    #"/",d7            * and get length of subdir name
  297.         beq.s    oblique         * if required.
  298.         addq.w    #1,a4
  299.         addq.w    #1,d0
  300.         bra.b    dir_loop
  301.  
  302.         cnop    0,4
  303. oblique        move.w    d0,d7            * d0 = dir name length
  304.         move.w    d0,d6        
  305.         subq.w    #1,d7
  306.         bsr.w    hash_name        * hash dir name into d0
  307.         move.l    $18(a0,d0.w*4),d0    * header block for this hash
  308.         beq.w    file_not_found
  309. get_dir_header    bsr.w    Get_block
  310.         tst.b    (a2)
  311.         bne.w    file_eror
  312.         bsr.w    compare_names
  313.         tst.w    d7
  314.         beq.s    next_in_chain
  315.         addq.w    #1,a4
  316.         move.l    a4,a6
  317.         bra.b    find_files_root_dir_loop
  318.  
  319.         cnop    0,4
  320. next_in_chain    move.l    $1f0(a0),d0
  321.         bne.b    get_dir_header
  322.         bra.b    file_not_found
  323.  
  324.         cnop    0,4
  325. root_dir    move.w    d0,d7            * length of file name
  326.         move.w    d0,d6
  327.         subq.w    #1,d7
  328.         bsr.b    hash_name    
  329.         move.l    $18(a0,d0.w*4),d0    * header block number for this hash
  330.         beq.b    file_not_foun